﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

using GameEngine.SceneGraph;

namespace Redland2
{
    public class Powerup : Entity
    {
        #region members

        private int _time;
        private int _duration;
        private int _ammount;

        #endregion members

        #region properties

        public int Duration
        {
            get { return _duration; }
            set { _duration = value; }
        }

        public int Ammount
        {
            get { return _ammount; }
            set { _ammount = value; }
        }

        #endregion properties

        #region constructors
        public Powerup(GameScene inputScene, int inputIndex, Vector2 inputPos): base(inputScene, inputIndex, GameScene.Current.Content.Load<Texture2D>("powerup-placeholder"), inputPos)
        {
            _time = 0;
            _duration = -1;
            _ammount = 0;
            this.type = "powerup";
        }
        #endregion construcors

        #region methods
        
        /// <summary>
        /// player calls this to pick up the powerup and remove it from the world
        /// </summary>
        /// <param name="inputOwner"></param>
        /// <returns></returns>
        public virtual Powerup Pickup(Player inputOwner)
        {
            this.Owner = inputOwner;
            this.Hide();
            this.Position = new Vector2(-1000, -1000);
            _time = 0;
            //this.scene.Drawables.Remove(this); 
            //this.scene._entities.Remove(this);
            return this;
        }

        /// <summary>
        /// Function called each time the player updates for over time powerups
        /// </summary>
        /// <param name="gametime"></param>
        public virtual void HeldEffect(GameTime gametime)
        {
        }

        /// <summary>
        /// Activate the powerup, returns if the powerup activated or not.
        /// </summary>
        /// <param name="gametime"></param>
        /// <returns></returns>
        public virtual bool Activate(GameTime gametime)
        {
            return true;
        }

        public override void Update(GameTime gameTime)
        {
            if (_duration >= 0 && (_time++ > _duration)) // does the durration compare mean that the time doesnt move unless the duration is positive?
                this.Kill();
            base.Update(gameTime);
        }

        public override bool offscreen()
        {
            return false;
        }
        #endregion method

    }
}
